package cn.hxlc.tie.demo.modular.ljt.equipment.util;

import cn.hxlc.tie.demo.core.error.MdmExceptionEnum;
import cn.hxlc.tie.model.exp.ServiceException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.commons.lang.StringUtils;

public class NumberUtil {
    public static void checkRepeatNumber(BaseMapper mapper, String number, Long id){
        if(StringUtils.isNotEmpty(number)){
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("enumber",number);
            if(id!=null){
                queryWrapper.ne("eid",id);
            }
            Integer count = mapper.selectCount(queryWrapper);
            if(count.intValue()>0){
                throw new ServiceException(MdmExceptionEnum.EXIST_ERROR.getCode(),"编号重复:"+number);
            }
        }
    }
}
